package com.my.Config;

import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;

@Component
@EnableWebMvc
public class mvcConfig implements WebMvcConfigurer {



  @Override
  public void configureViewResolvers(ViewResolverRegistry registry) {
//视图解析器相当于:
//    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
//    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
//    <property name="prefix" value="/WEB-INF/jsp/"/>
//    <property name="suffix" value=".jsp"/>
//</bean>
    registry.enableContentNegotiation(new MappingJackson2JsonView());
    registry.jsp("/WEB-INF/jsp/",".jsp");

  }

  @Override
  public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
    //如果从RequestMapping中映射不了,就交给servlet容器处理
    //相当于<mvc:default-servlet-handler default-servlet-name="myCustomDefaultServlet"/>
    configurer.enable();
  }

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**")
      .addResourceLocations("/public", "classpath:/static/")
      .setCachePeriod(31556926);
  }

}
